package com.oocl.servermanager;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.oocl.constant.LogLevel;
import com.oocl.server.ChatServer;
import com.oocl.util.ConsoleLogUtil;
import com.oocl.util.ResourceCloser;

public class ServerManager {
	private ChatServer currChatServer;
	
	public void start(){
		ServerSocket server = null;
		try {
			server = new ServerSocket(6666);
			ConsoleLogUtil.log("Manager server start success...", LogLevel.INFO);
			while(true){
				Socket socket = server.accept();
				ConsoleLogUtil.log("A user connected to the server", LogLevel.INFO);
				new ManagerThread(currChatServer, socket,this).start();
			}
		} catch (IOException e) {
			ConsoleLogUtil.log("Manager server start wrong!"+e.getMessage(), LogLevel.ERROR);
			ResourceCloser.release(null, null, null, server);
		}finally {
			ResourceCloser.release(null, null, null, server);
			ConsoleLogUtil.log("Chat server stop success...", LogLevel.INFO);
		}
	}

	public ChatServer getCurrChatServer() {
		return currChatServer;
	}

	public void setCurrChatServer(ChatServer currChatServer) {
		this.currChatServer = currChatServer;
	}
	
	
	
}
